package file;

import java.io.File;
import java.util.Arrays;
import java.util.List;

public class Doc {
	public Doc(String name, String path) {
		super();
		this.name = name;
		this.path = path;
	}

	public Doc(File file) {
		String orgPath = file.getPath();
		name = computeName(orgPath);
		path = computePath(orgPath);
		categoryName = computeCategoryName(orgPath);
	}

	private String computeCategoryName(String orgPath) {
		String str;
		List<String> fileNames = Arrays.asList(orgPath.split("/"));
		switch (fileNames.size()) {
		case 2:
			str = computeName(orgPath);
			break;
		default:
			str = fileNames.get(1);
			break;
		}
		return str;
	}

	private String computePath(String orgPath) {
		int lastDot = orgPath.lastIndexOf(".");
		return orgPath.substring(0, lastDot);
	}

	private String computeName(String orgPath) {
		int lastSlash = orgPath.lastIndexOf("/");
		int lastDot = orgPath.lastIndexOf(".");
		return orgPath.substring(lastSlash + 1, lastDot);
	}

	public String getCategoryName() {
		return categoryName;
	}

	String name;
	String path;
	String categoryName;

	public String getName() {
		return name;
	}

	public String getPath() {
		return path;
	}
}
